home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / terminal / sysline-.1 / sysline- / sysline-1.1 / colorsel < prev    next >
Encoding:
Text File  |  1996-03-14  |  3.7 KB  |  190 lines

  1. #!/bin/sh
  2.  
  3. # colorsel
  4. # killer-app to make an ANSI attribute/color string -- bjd
  5. # not all attributes are used here
  6.  
  7. TPUT=tcput
  8.  
  9. ${TPUT} clear
  10. #echo -en "\033[H\033[J"
  11.  
  12. # attributes:
  13. #  0 = all attributes off
  14. #  1 = intensity 2 (bold)
  15. #  2 = intensity 0 (half-bright)
  16. #  4 = underline on
  17. #  5 = blink on
  18. #  7 = reverse on  
  19. # 10 = G0/G1 charset
  20. # 11 = 1st alternate font
  21. # 12 = 2nd alternate font
  22. # 21 = intensity 1 (normal, default)
  23. # 22 = intensity 1 (normal, default)
  24. # 24 = underline off
  25. # 25 = blink off
  26. # 27 = reverse off
  27. # 38 = default fg, white underline
  28. # 39 = default fg, underline off
  29. # 49 = default bg
  30.  
  31. error()
  32. {
  33.     echo -en "\nError: $1"
  34.     ERROR=1
  35. }
  36.  
  37. choose()
  38. {
  39.     if [ ! "$4" = "-1" ]
  40.     then
  41.         PREV=$4
  42.     else
  43.         PREV=""
  44.     fi
  45.     ${TPUT} cup $1 0
  46.     echo -en "Choose $3 number: $PREV" >&2
  47.     ${TPUT} cup $1 $2
  48.     read answer
  49.     if [ "$answer" = "" ]
  50.     then
  51.         answer=$4
  52.     fi
  53.     if [ ! "$answer" = "-1" ]
  54.     then
  55.         ${TPUT} cup $1 $2
  56.         echo $answer"   "
  57.     fi
  58. }
  59.  
  60. CHR="*"
  61. echo -e "\n\t\t\t\tBJ's colorsel %^)"
  62. echo -e "\n\n\t\t\t\t\tBG"
  63. echo -e "     black    red      green    yellow   blue     magenta  cyan     white"
  64. echo -e "     40       41       42       43       44       45       46       47"
  65. for FG in 30 31 32 33 34 35 36 37
  66. do
  67.     if [ $FG -eq 33 ]
  68.     then
  69.         echo -n "F  $FG"
  70.     elif [ $FG -eq 34 ]
  71.     then
  72.         echo -n "G  $FG"
  73.     else
  74.         echo -en "   $FG"
  75.     fi
  76.     
  77.     for BG in 40 41 42 43 44 45 46 47
  78.     do
  79.         echo  -en "${BG};${FG}m${CHR}"
  80.         
  81.         echo  -en "${BG};${FG}m${CHR}"
  82.         echo  -en ";${BG};${FG}m${CHR}"
  83.         echo  -en ";7;${BG};${FG}m${CHR}"
  84.         echo  -en ";${BG};${FG}m${CHR}"
  85.         
  86.         echo  -en "${BG};${FG}m${CHR}"
  87.         echo  -en ";${BG};${FG}m${CHR}"
  88.         echo  -en ";7;${BG};${FG}m${CHR}"
  89.         echo  -en ";${BG};${FG}m${CHR}"
  90.         
  91.         #echo -en "${BG};${FG}m${CHR}"
  92.         #echo -en ";${BG};${FG}m${CHR}"
  93.     done
  94.     echo
  95. done
  96. ATTR_NRS="012345678"
  97. echo -e "     ${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}${ATTR_NRS}"
  98. echo -e "\t\t\t\t       ATTR"
  99.  
  100.  
  101. BG="-1"
  102. FG="-1"
  103. AT="-1"
  104. while [ 1 = 1 ]
  105. do
  106.     ERROR=0
  107.     ${TPUT} cup 19 0
  108.     #${TPUT} ed
  109.     choose 18 26 "background" $BG
  110.     BG=$answer
  111.     choose 19 26 "foreground" $FG
  112.     FG=$answer
  113.     choose 20 26 "attribute " $AT
  114.     AT=$answer
  115.  
  116.     if [ ! $BG = -1 ]
  117.     then
  118.         if [ $BG -lt 40 -o $BG -gt 47 ]
  119.         then
  120.             error "background out of range (should be empty or [40-47])"
  121.         fi
  122.     fi
  123.     if [ ! $FG = -1 ]
  124.     then
  125.         if [ $FG -lt 30 -o $FG -gt 37 ]
  126.         then
  127.             error "foreground out of range (should be empty or [30-37])"
  128.         fi
  129.     fi
  130.     if [ ! $AT = -1 ]
  131.     then
  132.         if [ $AT -gt 8 ]
  133.         then
  134.             error "attribute choice out of range (should be empty or [0-8])"
  135.         fi
  136.     fi
  137.  
  138.     if [ $ERROR -eq 0 ]
  139.     then
  140.         ${TPUT} ed
  141.         echo -n "Combined string         : "
  142.         SEP=";"
  143.         if    [ "$AT" = "-1" ]; then     STR="";    SEP="";
  144.         elif  [ "$AT" = "0" ]; then    STR="0";
  145.         elif  [ "$AT" = "1" ]; then    STR="1";
  146.         elif  [ "$AT" = "2" ]; then    STR="1;4";
  147.         elif  [ "$AT" = "3" ]; then    STR="1;4;7";
  148.         elif  [ "$AT" = "4" ]; then    STR="1;7";
  149.         elif  [ "$AT" = "5" ]; then    STR="2";
  150.         elif  [ "$AT" = "6" ]; then    STR="2;4";
  151.         elif  [ "$AT" = "7" ]; then    STR="2;4;7";
  152.         elif  [ "$AT" = "8" ]; then    STR="2;7";
  153.         #elif [ "$AT" = "9" ]; then#    STR="4";
  154.         #elif [ "$AT" = "A" ]; then#    STR="4;7";
  155.         fi
  156.         
  157.         if [ ! "$BG" = "-1" ]
  158.         then
  159.             STR="${STR}${SEP}${BG}"
  160.             SEP=";"
  161.         fi
  162.         
  163.         if [ ! "$FG" = "-1" ]
  164.         then
  165.             STR="${STR}${SEP}${FG}"
  166.         fi
  167.         
  168.         echo ${STR}"          "
  169.         if [ $ERROR -eq 1 ]
  170.         then
  171.             echo
  172.         fi
  173.  
  174.         if [ ! "${STR}" = "" ]
  175.         then
  176.             STR="\033[${STR}m"
  177.         fi
  178.         
  179.         echo -e "\n\n\nIs ${STR}this\033[m what you had in mind?"
  180.         echo -e "And then you could add a 5 attribute to make it \033[5m${STR}blink\033[m..."
  181.         
  182.         echo -n "Again? "
  183.         read answer
  184.         if [ "$answer" = "n" -o "$answer = "N" -o "$answer = "no" ]
  185.         then
  186.             exit
  187.         fi
  188.     fi
  189. done
  190.